package com.ict.web.dto;

import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
import com.ict.common.annotation.Excel;
import com.ict.common.utils.bean.BeanUtils;
import com.ict.common.utils.uuid.IdUtils;
import com.ict.web.controller.file.domain.YzqFile;
import com.ict.web.controller.file.dto.YzqFileDTO;
import com.ict.web.domain.AnnualDeclaration;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import javax.validation.constraints.NotNull;
import java.io.Serializable;
import java.math.BigDecimal;
import java.time.LocalDateTime;
import java.util.ArrayList;

@Data
public class AnnualDeclarationAddDto implements Serializable {

    private static final long serialVersionUID = 1L;

    /** 年度项目计划id */
    @ApiModelProperty(value = "年度项目计划id")
    @NotNull(message = "年度项目计划id不能为空")
    @JsonSerialize(using=ToStringSerializer.class)
    private Long planId;

    /** 项目名称 */
    @Excel(name = "项目名称")
    @ApiModelProperty(value = "项目名称")
    private String entryName;

    /** 项目类别:{0:建设类;1:购买服务类;2:运维类;3:其他} */
    @Excel(name = "项目类别:{0:建设类;1:购买服务类;2:运维类;3:其他}")
    @ApiModelProperty(value = "项目类别:{0:建设类;1:购买服务类;2:运维类;3:其他}")
    private String projectCategory;

    /** 项目投资估算（万元） */
    @Excel(name = "项目投资估算", readConverterExp = "万=元")
    @ApiModelProperty(value = "项目投资估算")
    private BigDecimal projectInvestmentEstimation;

    /** 资金来源 */
    @Excel(name = "资金来源")
    @ApiModelProperty(value = "资金来源")
    private String sourceOfFunds;

    /** 项目建议书（新建项目） */
    @Excel(name = "项目建议书", readConverterExp = "新=建项目")
    @ApiModelProperty(value = "项目建议书")
    private YzqFileDTO projectProposal;

    /**
     * 增补凭证
     */
    @ApiModelProperty(value = "项目建议书文件对象")
    private YzqFileDTO supplementaryVoucher;

    /** 项目建设理由 */
    @Excel(name = "项目建设理由")
    @ApiModelProperty(value = "项目建设理由")
    private String reasonsForProjectConstruction;

    /** 项目内容简介 */
    @Excel(name = "项目内容简介")
    @ApiModelProperty(value = "项目内容简介")
    private String projectContentIntroduction;

    /** 预期效果描述 */
    @Excel(name = "预期效果描述")
    @ApiModelProperty(value = "预期效果描述")
    private String expectedEffectDescription;

    /** 前期工作完成情况 */
    @ApiModelProperty(value = "前期工作完成情况")
    @Excel(name = "前期工作完成情况")
    private String workCompletion;

    /** 项目负责人 */
    @ApiModelProperty(value = "项目负责人")
    @Excel(name = "项目负责人")
    private String projectLeader;

    /** 负责人电话 */
    @ApiModelProperty(value = "负责人电话")
    @Excel(name = "负责人电话")
    private String telephoneNumber;

    /** 项目联系人 */
    @ApiModelProperty(value = "项目联系人")
    @Excel(name = "项目联系人")
    private String projectContact;

    /** 联系人电话 */
    @ApiModelProperty(value = "联系人电话")
    @Excel(name = "联系人电话")
    private String contactTelephone;

    /** 暂存标识（0：正常1：暂存） */
    @ApiModelProperty(value = "暂存标识（0：正常1：暂存）")
    @Excel(name = "暂存标识", readConverterExp = "0=：正常1：暂存")
    private String temporaryFlag;

    /** 建设单位 */
    @ApiModelProperty(value = "建设单位")
    @Excel(name = "建设单位")
    private String constructionUnit;

    /** 所属部门 */
    @ApiModelProperty(value = "所属部门")
    @Excel(name = "联系人电话")
    private String department;
    /**
     * 将 AnnualProjectPlanAddDto 转化为 AnnualProjectPlan
     *
     * @param dto 接收dto
     * @return HotelInfo
     */
    public static AnnualDeclaration of(AnnualDeclarationAddDto dto){
        AnnualDeclaration bean = new AnnualDeclaration();
        BeanUtils.copyProperties(dto,bean);

        //设置ID
        bean.setAnnualId(IdUtils.snowId());
        //设置创建时间
        bean.setCreateTime(LocalDateTime.now());
        //设置创建时间
        bean.setUpdateTime(LocalDateTime.now());
        //设置物理删除标记
        bean.setDelFlag("0");

        return bean;
    }
    /**
     * 将 AnnualProjectPlanAddDto中需传文件对象 转化为 file
     *
     * @param dto 接收dto
     * @return HotelInfo
     */
    public static ArrayList<YzqFile> toFile(AnnualDeclaration annualDeclaration,AnnualDeclarationAddDto dto){
        ArrayList<YzqFile> fileList = new ArrayList<>();
//        YzqFileDTO supplementaryVoucher = dto.getSupplementaryVoucher();
        YzqFileDTO projectProposal = dto.getProjectProposal();

//        YzqFile fileSu = new YzqFile();
//        fileSu.setId(String.valueOf(IdUtils.snowId()));
//        BeanUtils.copyProperties(supplementaryVoucher,fileSu);
//        fileList.add(fileSu);

        YzqFile filePro = new YzqFile();
        filePro.setId(String.valueOf(IdUtils.snowId()));
        BeanUtils.copyProperties(projectProposal,filePro);
        fileList.add(filePro);
        annualDeclaration.setProjectProposal(filePro.getId());
//        annualDeclaration.setUpdateTime();增补凭证的文件id暂不同步
        return fileList;
    }
}
